package com.cg.service.impl;

import com.cg.dao.InfoMapper;
import com.cg.dao.PatientMapper;
import com.cg.dto.Result;
import com.cg.dto.ResultEnum;
import com.cg.dto.ResultUtils;
import com.cg.entity.Info;
import com.cg.service.InfoService;
import com.cg.vo.PatientVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Info)表服务实现类
 *
 * @author chengong
 * @since 2024-01-07 14:45:28
 */
@Service("infoService")
public class InfoServiceImpl implements InfoService {
    @Resource
    private InfoMapper infoMapper;

    @Resource
    private PatientMapper patientMapper;

    /**
     * 授权
     */
    @Override
    public Result addInfo(String cardNum) {
        //根据codeNum查询就诊人详情
        PatientVo patientVo = patientMapper.queryPatientByCardNum(cardNum);
        if(patientVo == null){
            return ResultUtils.returnResult(ResultEnum.TOKEN_INFO_NULL);
        }
        Info info = new Info();
        info.setInfoCode(cardNum);
        info.setInfoName(patientVo.getPatientName()+"认证授权");
        info.setInfo("实名认证信息授权"+"\n"+"绑定个人信息后:"+patientVo.getPatientName()+"\n"
        +"证件类型:"+patientVo.getCarTypeName()+"\n"+"证件号:"+patientVo.getIdCard());
        Integer count = infoMapper.addInfo(info);
        if(count <= 0){
            return ResultUtils.returnResult(ResultEnum.TOKEN_INFO_NULL);
        }
        return ResultUtils.returnSuccess();
    }

    /**
     * 查询全部授权信息
     */
    @Override
    public List<Info> queryInfoList() {
        return infoMapper.queryInfoList();
    }

    /**
     * 根据授权名称查询授权信息
     */
    @Override
    public Info queryInfo(String infoName) {
        return infoMapper.queryInfo(infoName);
    }
}
